//
//  UIButton_Vehicle.m
//  EduCourse
//
//  Created by yanyan on 2017/8/9.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "UIButton_Vehicle.h"

@implementation UIButton_Vehicle
+(instancetype)buttonWithType:(UIButtonType)buttonType
{
    UIButton_Vehicle *btn = [UIButton_Vehicle buttonWithType:UIButtonTypeCustom];
    return btn;
}
- (void)settingsForButton:(UIButton_Vehicle*)btn{
    btn.isTitleBottom = true;
    btn.titleHeight = 20;
    btn.vPadding = 3;
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    btn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    //    btn.titleLabel.adjustsFontSizeToFitWidth = YES;
    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self settingsForButton:self];
    }
    return self;
}
-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
    if (_isTitleBottom){
        return CGRectMake(0, CGRectGetHeight(contentRect)-self.vPadding-self.titleHeight, CGRectGetWidth(contentRect), self.titleHeight);
    } else {
        return CGRectMake(0, 0, CGRectGetWidth(contentRect), self.titleHeight);
        
    }
}
-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat width = CGRectGetWidth(contentRect)< CGRectGetHeight(contentRect)-self.vPadding*2 - self.titleHeight?CGRectGetWidth(contentRect):CGRectGetHeight(contentRect)- self.vPadding*2 - self.titleHeight;
    if (_isTitleBottom){
        return CGRectMake((CGRectGetWidth(contentRect)-width)/2, self.vPadding, width, width);
    } else {
        return CGRectMake((CGRectGetWidth(contentRect)-width)/2, self.titleHeight+self.vPadding, width, width);
        
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
